%
% Status : main Dynare file
%
% Warning : this file is generated automatically by Dynare
%           from model file (.mod)

clearvars -global
clear_persistent_variables(fileparts(which('dynare')), false)
tic0 = tic;
% Define global variables.
global M_ options_ oo_ estim_params_ bayestopt_ dataset_ dataset_info estimation_info
options_ = [];
M_.fname = 'P15ra';
M_.dynare_version = '6.1';
oo_.dynare_version = '6.1';
options_.dynare_version = '6.1';
%
% Some global variables initialization
%
global_initialization;
M_.exo_names = cell(1,1);
M_.exo_names_tex = cell(1,1);
M_.exo_names_long = cell(1,1);
M_.exo_names(1) = {'e_z'};
M_.exo_names_tex(1) = {'e\_z'};
M_.exo_names_long(1) = {'e_z'};
M_.endo_names = cell(10,1);
M_.endo_names_tex = cell(10,1);
M_.endo_names_long = cell(10,1);
M_.endo_names(1) = {'y'};
M_.endo_names_tex(1) = {'y'};
M_.endo_names_long(1) = {'y'};
M_.endo_names(2) = {'c'};
M_.endo_names_tex(2) = {'c'};
M_.endo_names_long(2) = {'c'};
M_.endo_names(3) = {'k'};
M_.endo_names_tex(3) = {'k'};
M_.endo_names_long(3) = {'k'};
M_.endo_names(4) = {'i'};
M_.endo_names_tex(4) = {'i'};
M_.endo_names_long(4) = {'i'};
M_.endo_names(5) = {'n'};
M_.endo_names_tex(5) = {'n'};
M_.endo_names_long(5) = {'n'};
M_.endo_names(6) = {'y_n'};
M_.endo_names_tex(6) = {'y\_n'};
M_.endo_names_long(6) = {'y_n'};
M_.endo_names(7) = {'z'};
M_.endo_names_tex(7) = {'z'};
M_.endo_names_long(7) = {'z'};
M_.endo_names(8) = {'r'};
M_.endo_names_tex(8) = {'r'};
M_.endo_names_long(8) = {'r'};
M_.endo_names(9) = {'w'};
M_.endo_names_tex(9) = {'w'};
M_.endo_names_long(9) = {'w'};
M_.endo_names(10) = {'sigma_c'};
M_.endo_names_tex(10) = {'sigma\_c'};
M_.endo_names_long(10) = {'sigma_c'};
M_.endo_partitions = struct();
M_.param_names = cell(9,1);
M_.param_names_tex = cell(9,1);
M_.param_names_long = cell(9,1);
M_.param_names(1) = {'beta'};
M_.param_names_tex(1) = {'beta'};
M_.param_names_long(1) = {'beta'};
M_.param_names(2) = {'psi'};
M_.param_names_tex(2) = {'psi'};
M_.param_names_long(2) = {'psi'};
M_.param_names(3) = {'delta'};
M_.param_names_tex(3) = {'delta'};
M_.param_names_long(3) = {'delta'};
M_.param_names(4) = {'alpha'};
M_.param_names_tex(4) = {'alpha'};
M_.param_names_long(4) = {'alpha'};
M_.param_names(5) = {'rho_z'};
M_.param_names_tex(5) = {'rho\_z'};
M_.param_names_long(5) = {'rho_z'};
M_.param_names(6) = {'sigma_cbar'};
M_.param_names_tex(6) = {'sigma\_cbar'};
M_.param_names_long(6) = {'sigma_cbar'};
M_.param_names(7) = {'eta'};
M_.param_names_tex(7) = {'eta'};
M_.param_names_long(7) = {'eta'};
M_.param_names(8) = {'gamma'};
M_.param_names_tex(8) = {'gamma'};
M_.param_names_long(8) = {'gamma'};
M_.param_names(9) = {'ybar'};
M_.param_names_tex(9) = {'ybar'};
M_.param_names_long(9) = {'ybar'};
M_.param_partitions = struct();
M_.exo_det_nbr = 0;
M_.exo_nbr = 1;
M_.endo_nbr = 10;
M_.param_nbr = 9;
M_.orig_endo_nbr = 10;
M_.aux_vars = [];
M_.Sigma_e = zeros(1, 1);
M_.Correlation_matrix = eye(1, 1);
M_.H = 0;
M_.Correlation_matrix_ME = 1;
M_.sigma_e_is_diagonal = true;
M_.det_shocks = [];
M_.surprise_shocks = [];
M_.learnt_shocks = [];
M_.learnt_endval = [];
M_.heteroskedastic_shocks.Qvalue_orig = [];
M_.heteroskedastic_shocks.Qscale_orig = [];
M_.matched_irfs = {};
M_.matched_irfs_weights = {};
options_.linear = false;
options_.block = false;
options_.bytecode = false;
options_.use_dll = false;
options_.ramsey_policy = false;
options_.discretionary_policy = false;
M_.nonzero_hessian_eqs = [1 2 5 7 9 10];
M_.hessian_eq_zero = isempty(M_.nonzero_hessian_eqs);
M_.eq_nbr = 10;
M_.ramsey_orig_eq_nbr = 0;
M_.ramsey_orig_endo_nbr = 0;
M_.set_auxiliary_variables = exist(['./+' M_.fname '/set_auxiliary_variables.m'], 'file') == 2;
M_.epilogue_names = {};
M_.epilogue_var_list_ = {};
M_.orig_maximum_endo_lag = 1;
M_.orig_maximum_endo_lead = 1;
M_.orig_maximum_exo_lag = 0;
M_.orig_maximum_exo_lead = 0;
M_.orig_maximum_exo_det_lag = 0;
M_.orig_maximum_exo_det_lead = 0;
M_.orig_maximum_lag = 1;
M_.orig_maximum_lead = 1;
M_.orig_maximum_lag_with_diffs_expanded = 1;
M_.lead_lag_incidence = [
 0 3 13;
 0 4 14;
 1 5 0;
 0 6 0;
 0 7 0;
 0 8 0;
 2 9 0;
 0 10 0;
 0 11 0;
 0 12 15;]';
M_.nstatic = 5;
M_.nfwrd   = 3;
M_.npred   = 2;
M_.nboth   = 0;
M_.nsfwrd   = 3;
M_.nspred   = 2;
M_.ndynamic   = 5;
M_.dynamic_tmp_nbr = [16; 22; 31; 16; ];
M_.equations_tags = {
  1 , 'name' , '1' ;
  2 , 'name' , '2' ;
  3 , 'name' , 'sigma_c' ;
  4 , 'name' , '4' ;
  5 , 'name' , 'y' ;
  6 , 'name' , 'i' ;
  7 , 'name' , 'y_n' ;
  8 , 'name' , 'z' ;
  9 , 'name' , 'r' ;
  10 , 'name' , 'w' ;
};
M_.mapping.y.eqidx = [1 2 3 4 5 7 ];
M_.mapping.c.eqidx = [1 2 4 ];
M_.mapping.k.eqidx = [2 5 6 9 10 ];
M_.mapping.i.eqidx = [4 6 ];
M_.mapping.n.eqidx = [1 5 7 9 10 ];
M_.mapping.y_n.eqidx = [7 ];
M_.mapping.z.eqidx = [5 8 ];
M_.mapping.r.eqidx = [9 ];
M_.mapping.w.eqidx = [10 ];
M_.mapping.sigma_c.eqidx = [1 2 3 ];
M_.mapping.e_z.eqidx = [8 ];
M_.static_and_dynamic_models_differ = false;
M_.has_external_function = false;
M_.block_structure.time_recursive = false;
M_.block_structure.block(1).Simulation_Type = 1;
M_.block_structure.block(1).endo_nbr = 1;
M_.block_structure.block(1).mfs = 1;
M_.block_structure.block(1).equation = [ 8];
M_.block_structure.block(1).variable = [ 7];
M_.block_structure.block(1).is_linear = true;
M_.block_structure.block(1).NNZDerivatives = 2;
M_.block_structure.block(1).bytecode_jacob_cols_to_sparse = [1 2 ];
M_.block_structure.block(2).Simulation_Type = 8;
M_.block_structure.block(2).endo_nbr = 6;
M_.block_structure.block(2).mfs = 6;
M_.block_structure.block(2).equation = [ 4 5 6 2 3 1];
M_.block_structure.block(2).variable = [ 4 5 3 10 1 2];
M_.block_structure.block(2).is_linear = false;
M_.block_structure.block(2).NNZDerivatives = 21;
M_.block_structure.block(2).bytecode_jacob_cols_to_sparse = [3 7 8 9 10 11 12 16 17 18 ];
M_.block_structure.block(3).Simulation_Type = 1;
M_.block_structure.block(3).endo_nbr = 3;
M_.block_structure.block(3).mfs = 3;
M_.block_structure.block(3).equation = [ 10 9 7];
M_.block_structure.block(3).variable = [ 9 8 6];
M_.block_structure.block(3).is_linear = true;
M_.block_structure.block(3).NNZDerivatives = 3;
M_.block_structure.block(3).bytecode_jacob_cols_to_sparse = [4 5 6 ];
M_.block_structure.block(1).g1_sparse_rowval = int32([]);
M_.block_structure.block(1).g1_sparse_colval = int32([]);
M_.block_structure.block(1).g1_sparse_colptr = int32([]);
M_.block_structure.block(2).g1_sparse_rowval = int32([2 3 1 3 2 6 3 4 4 5 6 1 2 5 6 1 4 6 4 4 4 ]);
M_.block_structure.block(2).g1_sparse_colval = int32([3 3 7 7 8 8 9 9 10 10 10 11 11 11 11 12 12 12 16 17 18 ]);
M_.block_structure.block(2).g1_sparse_colptr = int32([1 1 1 3 3 3 3 5 7 9 12 16 19 19 19 19 20 21 22 ]);
M_.block_structure.block(3).g1_sparse_rowval = int32([]);
M_.block_structure.block(3).g1_sparse_colval = int32([]);
M_.block_structure.block(3).g1_sparse_colptr = int32([]);
M_.block_structure.variable_reordered = [ 7 4 5 3 10 1 2 9 8 6];
M_.block_structure.equation_reordered = [ 8 4 5 6 2 3 1 10 9 7];
M_.block_structure.incidence(1).lead_lag = -1;
M_.block_structure.incidence(1).sparse_IM = [
 5 3;
 6 3;
 8 7;
 9 3;
 10 3;
];
M_.block_structure.incidence(2).lead_lag = 0;
M_.block_structure.incidence(2).sparse_IM = [
 1 1;
 1 2;
 1 5;
 1 10;
 2 2;
 2 3;
 2 10;
 3 1;
 3 10;
 4 1;
 4 2;
 4 4;
 5 1;
 5 5;
 5 7;
 6 3;
 6 4;
 7 1;
 7 5;
 7 6;
 8 7;
 9 5;
 9 8;
 10 5;
 10 9;
];
M_.block_structure.incidence(3).lead_lag = 1;
M_.block_structure.incidence(3).sparse_IM = [
 2 1;
 2 2;
 2 10;
];
M_.block_structure.dyn_tmp_nbr = 18;
M_.state_var = [7 3 ];
M_.maximum_lag = 1;
M_.maximum_lead = 1;
M_.maximum_endo_lag = 1;
M_.maximum_endo_lead = 1;
oo_.steady_state = zeros(10, 1);
M_.maximum_exo_lag = 0;
M_.maximum_exo_lead = 0;
oo_.exo_steady_state = zeros(1, 1);
M_.params = NaN(9, 1);
M_.endo_trends = struct('deflator', cell(10, 1), 'log_deflator', cell(10, 1), 'growth_factor', cell(10, 1), 'log_growth_factor', cell(10, 1));
M_.NNZDerivatives = [34; 54; 56; ];
M_.dynamic_g1_sparse_rowval = int32([5 6 9 10 8 1 3 4 5 7 1 2 4 2 6 4 6 1 5 7 9 10 7 5 8 9 10 1 2 3 2 2 2 8 ]);
M_.dynamic_g1_sparse_colval = int32([3 3 3 3 7 11 11 11 11 11 12 12 12 13 13 14 14 15 15 15 15 15 16 17 17 18 19 20 20 20 21 22 30 31 ]);
M_.dynamic_g1_sparse_colptr = int32([1 1 1 5 5 5 5 6 6 6 6 11 14 16 18 23 24 26 27 28 31 32 33 33 33 33 33 33 33 33 34 35 ]);
M_.dynamic_g2_sparse_indices = int32([1 11 12 ;
1 11 15 ;
1 11 20 ;
1 12 12 ;
1 12 15 ;
1 12 20 ;
1 15 15 ;
1 15 20 ;
1 20 20 ;
2 21 22 ;
2 21 13 ;
2 21 30 ;
2 12 12 ;
2 12 20 ;
2 22 22 ;
2 22 13 ;
2 22 30 ;
2 13 13 ;
2 13 30 ;
2 20 20 ;
2 30 30 ;
5 3 3 ;
5 3 15 ;
5 3 17 ;
5 15 15 ;
5 15 17 ;
5 17 17 ;
7 11 15 ;
7 15 15 ;
9 3 3 ;
9 3 15 ;
9 15 15 ;
10 3 3 ;
10 3 15 ;
10 15 15 ;
]);
M_.dynamic_g3_sparse_indices = int32([1 11 12 12 ;
1 11 12 15 ;
1 11 12 20 ;
1 11 15 15 ;
1 11 15 20 ;
1 11 20 20 ;
1 12 12 12 ;
1 12 12 15 ;
1 12 12 20 ;
1 12 15 15 ;
1 12 15 20 ;
1 12 20 20 ;
1 15 15 15 ;
1 15 15 20 ;
1 15 20 20 ;
1 20 20 20 ;
2 21 22 22 ;
2 21 22 13 ;
2 21 22 30 ;
2 21 13 13 ;
2 21 13 30 ;
2 21 30 30 ;
2 12 12 12 ;
2 12 12 20 ;
2 12 20 20 ;
2 22 22 22 ;
2 22 22 13 ;
2 22 22 30 ;
2 22 13 13 ;
2 22 13 30 ;
2 22 30 30 ;
2 13 13 13 ;
2 13 13 30 ;
2 13 30 30 ;
2 20 20 20 ;
2 30 30 30 ;
5 3 3 3 ;
5 3 3 15 ;
5 3 3 17 ;
5 3 15 15 ;
5 3 15 17 ;
5 3 17 17 ;
5 15 15 15 ;
5 15 15 17 ;
5 15 17 17 ;
5 17 17 17 ;
7 11 15 15 ;
7 15 15 15 ;
9 3 3 3 ;
9 3 3 15 ;
9 3 15 15 ;
9 15 15 15 ;
10 3 3 3 ;
10 3 3 15 ;
10 3 15 15 ;
10 15 15 15 ;
]);
M_.lhs = {
'(alpha-1)*gamma*y/n*(c^(1-sigma_c)*log(c)/(sigma_c-1)+(c^(1-sigma_c)-1)/(sigma_c-1)^2)'; 
'c^(-sigma_c)+alpha*gamma*beta*(c(1)^(1-sigma_c(1))*log(c(1))/(sigma_c(1)-1)+(c(1)^(1-sigma_c(1))-1)/(sigma_c(1)-1)^2)*y(1)/k'; 
'sigma_c'; 
'c+i'; 
'y'; 
'i'; 
'y_n'; 
'z'; 
'r'; 
'w'; 
};
M_.static_tmp_nbr = [10; 6; 0; 0; ];
M_.block_structure_stat.block(1).Simulation_Type = 3;
M_.block_structure_stat.block(1).endo_nbr = 1;
M_.block_structure_stat.block(1).mfs = 1;
M_.block_structure_stat.block(1).equation = [ 8];
M_.block_structure_stat.block(1).variable = [ 7];
M_.block_structure_stat.block(2).Simulation_Type = 6;
M_.block_structure_stat.block(2).endo_nbr = 6;
M_.block_structure_stat.block(2).mfs = 6;
M_.block_structure_stat.block(2).equation = [ 2 3 4 5 6 1];
M_.block_structure_stat.block(2).variable = [ 3 10 2 1 4 5];
M_.block_structure_stat.block(3).Simulation_Type = 1;
M_.block_structure_stat.block(3).endo_nbr = 3;
M_.block_structure_stat.block(3).mfs = 3;
M_.block_structure_stat.block(3).equation = [ 10 9 7];
M_.block_structure_stat.block(3).variable = [ 9 8 6];
M_.block_structure_stat.variable_reordered = [ 7 3 10 2 1 4 5 9 8 6];
M_.block_structure_stat.equation_reordered = [ 8 2 3 4 5 6 1 10 9 7];
M_.block_structure_stat.incidence.sparse_IM = [
 1 1;
 1 2;
 1 5;
 1 10;
 2 1;
 2 2;
 2 3;
 2 10;
 3 1;
 3 10;
 4 1;
 4 2;
 4 4;
 5 1;
 5 3;
 5 5;
 5 7;
 6 3;
 6 4;
 7 1;
 7 5;
 7 6;
 8 7;
 9 3;
 9 5;
 9 8;
 10 3;
 10 5;
 10 9;
];
M_.block_structure_stat.tmp_nbr = 12;
M_.block_structure_stat.block(1).g1_sparse_rowval = int32([1 ]);
M_.block_structure_stat.block(1).g1_sparse_colval = int32([1 ]);
M_.block_structure_stat.block(1).g1_sparse_colptr = int32([1 2 ]);
M_.block_structure_stat.block(2).g1_sparse_rowval = int32([1 4 5 1 2 6 1 3 6 1 2 3 4 6 3 5 4 6 ]);
M_.block_structure_stat.block(2).g1_sparse_colval = int32([1 1 1 2 2 2 3 3 3 4 4 4 4 4 5 5 6 6 ]);
M_.block_structure_stat.block(2).g1_sparse_colptr = int32([1 4 7 10 15 17 19 ]);
M_.block_structure_stat.block(3).g1_sparse_rowval = int32([]);
M_.block_structure_stat.block(3).g1_sparse_colval = int32([]);
M_.block_structure_stat.block(3).g1_sparse_colptr = int32([]);
M_.static_g1_sparse_rowval = int32([1 2 3 4 5 7 1 2 4 2 5 6 9 10 4 6 1 5 7 9 10 7 5 8 9 10 1 2 3 ]);
M_.static_g1_sparse_colval = int32([1 1 1 1 1 1 2 2 2 3 3 3 3 3 4 4 5 5 5 5 5 6 7 7 8 9 10 10 10 ]);
M_.static_g1_sparse_colptr = int32([1 7 10 15 17 22 23 25 26 27 30 ]);
clc;            
close all;      
M_.params(4) = 0.36;
alpha = M_.params(4);
M_.params(1) = 0.99;
beta = M_.params(1);
M_.params(3) = 0.02;
delta = M_.params(3);
M_.params(7) = 1.333333333333333;
eta = M_.params(7);
M_.params(2) = 16.4334;
psi = M_.params(2);
M_.params(5) = 0.95;
rho_z = M_.params(5);
sigma_z     = 0.007;            
M_.params(6) = 3.00;
sigma_cbar = M_.params(6);
M_.params(9) = 1.215344;
ybar = M_.params(9);
M_.params(8) = 1.50;
gamma = M_.params(8);
%
% INITVAL instructions
%
options_.initval_file = false;
oo_.steady_state(3) = 14.5;
oo_.steady_state(1) = 1.21;
oo_.steady_state(2) = 0.91;
oo_.steady_state(5) = 0.3;
oo_.steady_state(7) = 0;
oo_.exo_steady_state(1) = 0;
if M_.exo_nbr > 0
	oo_.exo_simul = ones(M_.maximum_lag,1)*oo_.exo_steady_state';
end
if M_.exo_det_nbr > 0
	oo_.exo_det_simul = ones(M_.maximum_lag,1)*oo_.exo_det_steady_state';
end
%
% SHOCKS instructions
%
M_.exo_det_length = 0;
M_.Sigma_e(1, 1) = sigma_z^2;
steady;
oo_.dr.eigval = check(M_,options_,oo_);
SSmatrix=oo_.steady_state;
columnlabeldesc = {'Steady-State'};
rowlabeldesc = {'$y$', '$c$' ,'$k$' ,'$i$', '$n$', '$y/n$',  '$z$' ,'$r$', '$w$', '$\sigma_c$'};
matrix2latex(SSmatrix, 'steady_ra_P15.tex','rowLabels', rowlabeldesc, 'columnLabels', columnlabeldesc,'format', '%-6.4f', 'size', 'footnotesize', 'alignment', 'c');
set_dynare_seed(27031983);
options_.k_order_solver = true;
options_.drop = 100;
options_.irf = 200;
options_.order = 3;
options_.periods = 2200;
var_list_ = {'y';'c';'k';'i';'n';'y_n';'r';'w';'sigma_c'};
[info, oo_, options_, M_] = stoch_simul(M_, options_, oo_, var_list_);
y_e_z=oo_.irfs.y_e_z;
c_e_z=oo_.irfs.c_e_z;
i_e_z=oo_.irfs.i_e_z;
k_e_z=oo_.irfs.k_e_z;
n_e_z=oo_.irfs.n_e_z;
y_n_e_z=oo_.irfs.y_n_e_z;
r_e_z=oo_.irfs.r_e_z;
w_e_z=oo_.irfs.w_e_z;
sigma_c_e_z=oo_.irfs.sigma_c_e_z;
fig=figure;
subplot(1,1,1);
plot(y_e_z, 'r', 'LineWidth', 2.5);
title('Output', 'fontweight', 'bold','FontSize',18);
xlabel('Period','FontSize',18);
ylabel('Change','FontSize',18);
xt = get(gca, 'XTick');
set(gca, 'FontSize', 18);
grid;
print(fig,'z_y_ra_P15','-dpng')
fig=figure;
subplot(1,1,1);
plot(c_e_z, 'g', 'LineWidth', 2.5);
title('Consumption', 'fontweight', 'bold','FontSize',18);
xlabel('Period','FontSize',18);
ylabel('Change','FontSize',18);
xt = get(gca, 'XTick');
set(gca, 'FontSize', 18);
grid;
print(fig,'z_c_ra_P15','-dpng')
fig=figure;
subplot(1,1,1);
plot(i_e_z, 'y', 'LineWidth', 2.5);
title('Investment', 'fontweight', 'bold','FontSize',18);
xlabel('Period','FontSize',18);
ylabel('Change','FontSize',18);
xt = get(gca, 'XTick');
set(gca, 'FontSize', 18);
grid;
print(fig,'z_i_ra_P15','-dpng')
fig=figure;
subplot(1,1,1);
plot(k_e_z, 'b', 'LineWidth', 2.5);
title('Capital', 'fontweight', 'bold','FontSize',18);
xlabel('Period','FontSize',18);
ylabel('Change','FontSize',18);
xt = get(gca, 'XTick');
set(gca, 'FontSize', 18);
grid;
print(fig,'z_k_ra_P15','-dpng')
fig=figure;
subplot(1,1,1);
plot(n_e_z, 'm', 'LineWidth', 2.5);
title('Labor', 'fontweight', 'bold','FontSize',18);
xlabel('Period','FontSize',18);
ylabel('Change','FontSize',18);
xt = get(gca, 'XTick');
set(gca, 'FontSize', 18);
grid;
print(fig,'z_n_ra_P15','-dpng')
fig=figure;
subplot(1,1,1);
plot(y_n_e_z, 'r', 'LineWidth', 2.5);
title('Output per Labor', 'fontweight', 'bold','FontSize',18);
xlabel('Period','FontSize',18);
ylabel('Change','FontSize',18);
xt = get(gca, 'XTick');
set(gca, 'FontSize', 18);
grid;
print(fig,'z_y_n_ra_P15','-dpng')
fig=figure;
subplot(1,1,1);
plot(r_e_z, 'k', 'LineWidth', 2.5);
title('Real Rental Price of Capital', 'fontweight', 'bold','FontSize',18);
xlabel('Period','FontSize',18);
ylabel('Change','FontSize',18);
xt = get(gca, 'XTick');
set(gca, 'FontSize', 18);
grid;
print(fig,'z_r_ra_P15','-dpng')
fig=figure;
subplot(1,1,1);
plot(w_e_z, 'c', 'LineWidth', 2.5);
title('Real Wage', 'fontweight', 'bold','FontSize',18);
xlabel('Period','FontSize',18);
ylabel('Change','FontSize',18);
xt = get(gca, 'XTick');
set(gca, 'FontSize', 18);
grid;
print(fig,'z_w_ra_P15','-dpng')
fig=figure;
subplot(1,1,1);
plot(sigma_c_e_z, 'b', 'LineWidth', 2.5);
title('Risk Aversion', 'fontweight', 'bold','FontSize',18);
xlabel('Period','FontSize',18);
ylabel('Change','FontSize',18);
xt = get(gca, 'XTick');
set(gca, 'FontSize', 18);
grid;
print(fig,'z_sigma_c_z_ra_P15','-dpng')
total_sim = 2100;
y_sim=oo_.endo_simul(1,:)';
c_sim=oo_.endo_simul(2,:)';
k_sim=oo_.endo_simul(3,:)';
i_sim=oo_.endo_simul(4,:)';
n_sim=oo_.endo_simul(5,:)';
y_n_sim=oo_.endo_simul(6,:)';
z_sim=oo_.endo_simul(7,:)';
r_sim=oo_.endo_simul(8,:)';
w_sim=oo_.endo_simul(9,:)';
sigma_c_sim=oo_.endo_simul(10,:)';
[yt,yd]=hp(log(y_sim(101:total_sim,:)),1600);
[ct,cd]=hp(log(c_sim(101:total_sim,:)),1600);
[it,id]=hp(log(i_sim(101:total_sim,:)),1600);
[kt,kd]=hp(log(k_sim(101:total_sim,:)),1600);
[nt,nd]=hp(log(n_sim(101:total_sim,:)),1600);
[y_nt,y_nd]=hp(log(y_n_sim(101:total_sim,:)),1600);
[rt,rd]=hp(r_sim(101:total_sim,:),1600);
[wt,wd]=hp(log(w_sim(101:total_sim,:)),1600);
STDEV_y = std(yd);     
STDEV_c = std(cd);
STDEV_inv = std(id);
STDEV_k = std(kd);
STDEV_n = std(nd); 
STDEV_y_n = std(y_nd);
STDEV_r = std(rd);
STDEV_w = std(wd);
STDEV=[STDEV_y STDEV_c STDEV_inv STDEV_k STDEV_n STDEV_y_n STDEV_r STDEV_w]';
RELSTDEV=STDEV./STDEV_y;
T = 2000;
CORR_y = [corr2(yd(1:T-5),yd(6:T)),corr2(yd(1:T-4),yd(5:T)),corr2(yd(1:T-3),yd(4:T)),corr2(yd(1:T-2),yd(3:T)), ...
                 corr2(yd(1:T-1),yd(2:T)),corr2(yd(1:T),yd(1:T)), corr2(yd(2:T),yd(1:T-1)) , corr2(yd(3:T),yd(1:T-2)) ...
                 corr2(yd(4:T),yd(1:T-3)),corr2(yd(5:T),yd(1:T-4)),corr2(yd(6:T),yd(1:T-5))]';
CORR_c = [corr2(cd(1:T-5),yd(6:T)),corr2(cd(1:T-4),yd(5:T)),corr2(cd(1:T-3),yd(4:T)),corr2(cd(1:T-2),yd(3:T)), ...
                 corr2(cd(1:T-1),yd(2:T)),corr2(cd(1:T),yd(1:T)), corr2(cd(2:T),yd(1:T-1)) , corr2(cd(3:T),yd(1:T-2)) ...
                 corr2(cd(4:T),yd(1:T-3)),corr2(cd(5:T),yd(1:T-4)),corr2(cd(6:T),yd(1:T-5))]';
CORR_i = [corr2(id(1:T-5),yd(6:T)),corr2(id(1:T-4),yd(5:T)),corr2(id(1:T-3),yd(4:T)),corr2(id(1:T-2),yd(3:T)), ...
                 corr2(id(1:T-1),yd(2:T)),corr2(id(1:T),yd(1:T)), corr2(id(2:T),yd(1:T-1)) , corr2(id(3:T),yd(1:T-2)) ...
                 corr2(id(4:T),yd(1:T-3)),corr2(id(5:T),yd(1:T-4)),corr2(id(6:T),yd(1:T-5))]';
CORR_k = [corr2(kd(1:T-5),yd(6:T)),corr2(kd(1:T-4),yd(5:T)),corr2(kd(1:T-3),yd(4:T)),corr2(kd(1:T-2),yd(3:T)), ...
                 corr2(kd(1:T-1),yd(2:T)),corr2(kd(1:T),yd(1:T)), corr2(kd(2:T),yd(1:T-1)) , corr2(kd(3:T),yd(1:T-2)) ...
                 corr2(kd(4:T),yd(1:T-3)),corr2(kd(5:T),yd(1:T-4)),corr2(kd(6:T),yd(1:T-5))]';
CORR_n = [corr2(nd(1:T-5),yd(6:T)),corr2(nd(1:T-4),yd(5:T)),corr2(nd(1:T-3),yd(4:T)),corr2(nd(1:T-2),yd(3:T)), ...
                 corr2(nd(1:T-1),yd(2:T)),corr2(nd(1:T),yd(1:T)), corr2(nd(2:T),yd(1:T-1)) , corr2(nd(3:T),yd(1:T-2)) ...
                 corr2(nd(4:T),yd(1:T-3)),corr2(nd(5:T),yd(1:T-4)),corr2(nd(6:T),yd(1:T-5))]';
CORR_y_n = [corr2(y_nd(1:T-5),yd(6:T)),corr2(y_nd(1:T-4),yd(5:T)),corr2(y_nd(1:T-3),yd(4:T)),corr2(y_nd(1:T-2),yd(3:T)), ...
                 corr2(y_nd(1:T-1),yd(2:T)),corr2(y_nd(1:T),yd(1:T)), corr2(y_nd(2:T),yd(1:T-1)) , corr2(y_nd(3:T),yd(1:T-2)) ...
                 corr2(y_nd(4:T),yd(1:T-3)),corr2(y_nd(5:T),yd(1:T-4)),corr2(y_nd(6:T),yd(1:T-5))]';
CORR_r = [corr2(rd(1:T-5),yd(6:T)),corr2(rd(1:T-4),yd(5:T)),corr2(rd(1:T-3),yd(4:T)),corr2(rd(1:T-2),yd(3:T)), ...
                 corr2(rd(1:T-1),yd(2:T)),corr2(rd(1:T),yd(1:T)), corr2(rd(2:T),yd(1:T-1)) , corr2(rd(3:T),yd(1:T-2)) ...
                 corr2(rd(4:T),yd(1:T-3)),corr2(rd(5:T),yd(1:T-4)),corr2(rd(6:T),yd(1:T-5))]';
CORR_w = [corr2(wd(1:T-5),yd(6:T)),corr2(wd(1:T-4),yd(5:T)),corr2(wd(1:T-3),yd(4:T)),corr2(wd(1:T-2),yd(3:T)), ...
                 corr2(wd(1:T-1),yd(2:T)),corr2(wd(1:T),yd(1:T)), corr2(wd(2:T),yd(1:T-1)) , corr2(wd(3:T),yd(1:T-2)) ...
                 corr2(wd(4:T),yd(1:T-3)),corr2(wd(5:T),yd(1:T-4)),corr2(wd(6:T),yd(1:T-5))]';
CORRMATRIX=[CORR_y CORR_c CORR_i CORR_k CORR_n CORR_y_n CORR_r CORR_w]';
acorr_y=autocorr(yd,1);
acorr_y_1=acorr_y(2,1);
acorr_c=autocorr(cd,1);
acorr_c_1=acorr_c(2,1);
acorr_k=autocorr(kd,1);
acorr_k_1=acorr_k(2,1);
acorr_i=autocorr(id,1);
acorr_i_1=acorr_i(2,1);
acorr_n=autocorr(nd,1);
acorr_n_1=acorr_n(2,1);
acorr_y_n=autocorr(y_nd,1);
acorr_y_n_1=acorr_y_n(2,1);
acorr_r=autocorr(rd,1);
acorr_r_1=acorr_r(2,1);
acorr_w=autocorr(wd,1);
acorr_w_1=acorr_w(2,1);
ACORR=[acorr_y_1 acorr_c_1 acorr_i_1 acorr_k_1 acorr_n_1 acorr_y_n_1 acorr_r_1 acorr_w_1]';
BUSINESSCYCLEMATRIX=[STDEV  RELSTDEV  CORRMATRIX ACORR];
TableDescriptive=BUSINESSCYCLEMATRIX;
columnlabeldesc={'Std.', 'Rel. Std.','$x(-5)$','$x(-4)$', '$x(-3)$', '$x(-2)$','$x(-1)$','$x(0)$','$x(+1)$','$x(+2)$','$x(+3)$','$x(+4)$','$x(+5)$','AR(1)'};
rowlabeldesc = {'$y$', '$c$' , '$i$' ,'$k$', '$n$', '$y/n$',  '$r$' ,'$w$'};
matrix2latex(TableDescriptive, 'tableDescriptive_ra_P15.tex','rowLabels', rowlabeldesc, 'columnLabels', columnlabeldesc,'format', '%-6.4f', 'size', 'footnotesize', 'alignment', 'c');
val=(1:1:2200);
fig=figure;
plot(val,sigma_c_sim, 'b', 'LineWidth', 2.5);
title('Risk Aversion (\sigma_c)', 'fontweight', 'bold','FontSize',18);
xlabel('Period','FontSize',18);
ylabel('\sigma_c','FontSize',18);
xt = get(gca, 'XTick');
xlim([0,2200]);
set(gca, 'FontSize', 18);
grid;
print(fig,'sigma_c_ra_P15','-dpng')


oo_.time = toc(tic0);
disp(['Total computing time : ' dynsec2hms(oo_.time) ]);
if ~exist([M_.dname filesep 'Output'],'dir')
    mkdir(M_.dname,'Output');
end
save([M_.dname filesep 'Output' filesep 'P15ra_results.mat'], 'oo_', 'M_', 'options_');
if exist('estim_params_', 'var') == 1
  save([M_.dname filesep 'Output' filesep 'P15ra_results.mat'], 'estim_params_', '-append');
end
if exist('bayestopt_', 'var') == 1
  save([M_.dname filesep 'Output' filesep 'P15ra_results.mat'], 'bayestopt_', '-append');
end
if exist('dataset_', 'var') == 1
  save([M_.dname filesep 'Output' filesep 'P15ra_results.mat'], 'dataset_', '-append');
end
if exist('estimation_info', 'var') == 1
  save([M_.dname filesep 'Output' filesep 'P15ra_results.mat'], 'estimation_info', '-append');
end
if exist('dataset_info', 'var') == 1
  save([M_.dname filesep 'Output' filesep 'P15ra_results.mat'], 'dataset_info', '-append');
end
if exist('oo_recursive_', 'var') == 1
  save([M_.dname filesep 'Output' filesep 'P15ra_results.mat'], 'oo_recursive_', '-append');
end
if exist('options_mom_', 'var') == 1
  save([M_.dname filesep 'Output' filesep 'P15ra_results.mat'], 'options_mom_', '-append');
end
disp('Note: 10 warning(s) encountered in the preprocessor')
if ~isempty(lastwarn)
  disp('Note: warning(s) encountered in MATLAB/Octave code')
end
